

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="“ 常在河边走，哪能不湿鞋。” ——若发现文章内容有误，敬请指正，望不吝赐教，感谢!@[toc]  以往记录  Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…   Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境">
<meta property="og:type" content="article">
<meta property="og:title" content="Web项目实战 _ 购物系统v2.0 _ 开发记录（八）前后端分离初步思路 _ JS处理URL参数实用函数 _ AJAX 向后台传递Map类型数据 _ MyBatis多表查询优化">
<meta property="og:url" content="http://example.com/2022/02/17/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E5%85%AB%EF%BC%89%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB%E5%88%9D%E6%AD%A5%E6%80%9D%E8%B7%AF%20_%20JS%E5%A4%84%E7%90%86URL%E5%8F%82%E6%95%B0%E5%AE%9E%E7%94%A8%E5%87%BD%E6%95%B0%20_%20AJAX%20%E5%90%91%E5%90%8E%E5%8F%B0%E4%BC%A0%E9%80%92Map%E7%B1%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%20_%20MyBatis%E5%A4%9A%E8%A1%A8%E6%9F%A5%E8%AF%A2%E4%BC%98%E5%8C%96/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="“ 常在河边走，哪能不湿鞋。” ——若发现文章内容有误，敬请指正，望不吝赐教，感谢!@[toc]  以往记录  Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…   Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/8cfb712ef93e4c1ab978277c8bf18b1b.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/a2c63ef0e754480fb1cf4acd0e48a4e4.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/00c9e3ca41584a4da03d1b2d790ce133.png">
<meta property="article:published_time" content="2022-02-17T05:50:30.000Z">
<meta property="article:modified_time" content="2022-08-22T15:50:39.825Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="JavaWeb">
<meta property="article:tag" content="项目实战:购物系统v2.0">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/8cfb712ef93e4c1ab978277c8bf18b1b.png">
  
  
  
  <title>Web项目实战 _ 购物系统v2.0 _ 开发记录（八）前后端分离初步思路 _ JS处理URL参数实用函数 _ AJAX 向后台传递Map类型数据 _ MyBatis多表查询优化 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Web项目实战 _ 购物系统v2.0 _ 开发记录（八）前后端分离初步思路 _ JS处理URL参数实用函数 _ AJAX 向后台传递Map类型数据 _ MyBatis多表查询优化"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-02-17 13:50" pubdate>
          2022年2月17日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          19k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          158 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Web项目实战 _ 购物系统v2.0 _ 开发记录（八）前后端分离初步思路 _ JS处理URL参数实用函数 _ AJAX 向后台传递Map类型数据 _ MyBatis多表查询优化</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <blockquote>
<p>“ 常在河边走，哪能不湿鞋。” ——若发现文章内容有误，敬请指正，望不吝赐教，感谢!<br>@[toc]</p>
</blockquote>
<h1 id="以往记录"><a href="#以往记录" class="headerlink" title="以往记录"></a>以往记录</h1><hr>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122722369">Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122726356">Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBatis | 基于Bootstrap实现登陆页面| 图片验证码接口</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122743352">Web项目实战 | 购物系统v2.0 | 开发记录（三）分页显示 | 根据商品名称进行模糊查询</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122773805">Web项目实战 | 购物系统v2.0 | 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 | 使用省市区三级联动 | 使用JQuery 插件实现图片上传</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122787974">Web项目实战 | 购物系统v2.0 | 开发记录（五）| 使用base64编码实现头像修改 | 用户个人信息修改 | JQuery动态提示</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122799137">Web项目实战 | 购物系统v2.0 | 开发记录（六）商品详情页面 | 游客访问主页 | 运用Bootstrap4轻量级弹窗实现提示</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://editor.csdn.net/md/?articleId=122849396">Web项目实战 | 购物系统v2.0 | 开发记录（七）SpringBoot整合Shiro框架进行身份认证 | Shiro 加盐(MD5+Salt)验证登陆 | 数据表结构优化避免外键+设置中间表</a></p>
</blockquote>
<h1 id="一、使用JQuery设计工具函数处理URL"><a href="#一、使用JQuery设计工具函数处理URL" class="headerlink" title="一、使用JQuery设计工具函数处理URL"></a>一、使用JQuery设计工具函数处理URL</h1><hr>
<p>URL的作用非同小可，比如在百度搜索CSDN，观察地址栏可以发现有许多参数。<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/e966884c1bf94324b62fbcd97ae45c35.png#pic_center">https://img-blog.csdnimg.cn/e966884c1bf94324b62fbcd97ae45c35.png#pic_center</a> &#x3D;60%x)<br>这些参数可以传输到SpringMVC的<code>Controller层</code>，后期有许多的用途，比如查询一个用户的映射地址为<code>user/query</code>，这时可以给它添加一个参数表示查询的用户信息，比如<code>user/query?id=1</code>，这时则表示查询id为1的用户，笔者通过URL的处理，实现了后台管理系统中用户信息多个条件搜索的功能。</p>
<p>JS实现代码：<code>urlUtil.js</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-comment">// 添加 或者 修改 url中参数的值</span><br><span class="hljs-keyword">function</span> <span class="hljs-title function_">clearURIExceptPageNow</span>(<span class="hljs-params"></span>)&#123;<br>    <span class="hljs-keyword">return</span> <span class="hljs-variable language_">document</span>.<span class="hljs-property">location</span>.<span class="hljs-property">href</span>.<span class="hljs-title function_">split</span>(<span class="hljs-string">&#x27;&amp;&#x27;</span>)[<span class="hljs-number">0</span>]<br>&#125;<br><br><span class="hljs-keyword">function</span> <span class="hljs-title function_">getUrlParam</span>(<span class="hljs-params">thisURL, name</span>) &#123;<br>    <span class="hljs-keyword">let</span> array = <span class="hljs-keyword">new</span> <span class="hljs-title class_">RegExp</span>(name + <span class="hljs-string">&#x27;=([^&amp;]*)&#x27;</span>).<span class="hljs-title function_">exec</span>(thisURL);<br>    <span class="hljs-keyword">return</span> (array == <span class="hljs-literal">null</span> || array.<span class="hljs-property">length</span> &lt; <span class="hljs-number">1</span>)? <span class="hljs-string">&#x27;&#x27;</span> : <span class="hljs-built_in">decodeURI</span>(array[<span class="hljs-number">1</span>]);<br>&#125;<br><br><span class="hljs-keyword">function</span> <span class="hljs-title function_">updateUrlParam</span>(<span class="hljs-params">thisURL, name, val</span>) &#123;<br>    thisURL = <span class="hljs-built_in">decodeURI</span>(thisURL)<br>    <span class="hljs-comment">// 如果 url中包含这个参数 则修改</span><br>    <span class="hljs-keyword">if</span> (thisURL.<span class="hljs-title function_">indexOf</span>(name+<span class="hljs-string">&#x27;=&#x27;</span>) &gt; <span class="hljs-number">0</span>) &#123;<br>        <span class="hljs-keyword">var</span> v = <span class="hljs-title function_">getUrlParam</span>(thisURL, name);<br>        <span class="hljs-keyword">if</span> (v != <span class="hljs-literal">null</span>) &#123;<br>            <span class="hljs-comment">// 是否包含参数</span><br>            thisURL = thisURL.<span class="hljs-title function_">replace</span>(name + <span class="hljs-string">&#x27;=&#x27;</span> + v, name + <span class="hljs-string">&#x27;=&#x27;</span> + val);<br>        &#125;<br>        <span class="hljs-keyword">else</span> &#123;<br>            thisURL = thisURL.<span class="hljs-title function_">replace</span>(name + <span class="hljs-string">&#x27;=&#x27;</span>, name + <span class="hljs-string">&#x27;=&#x27;</span> + val);<br>        &#125;<br><br>    &#125; <span class="hljs-comment">// 不包含这个参数 则添加</span><br>    <span class="hljs-keyword">else</span> &#123;<br>        <span class="hljs-keyword">if</span> (thisURL.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">&quot;?&quot;</span>) &gt; <span class="hljs-number">0</span>) &#123;<br>            thisURL = thisURL + <span class="hljs-string">&quot;&amp;&quot;</span> + name + <span class="hljs-string">&quot;=&quot;</span> + val;<br>        &#125;<br>        <span class="hljs-keyword">else</span> &#123;<br>            thisURL = thisURL + <span class="hljs-string">&quot;?&quot;</span> + name + <span class="hljs-string">&quot;=&quot;</span> + val;<br>        &#125;<br>    &#125;<br>    <span class="hljs-keyword">return</span> thisURL;<br>&#125;<br><span class="hljs-keyword">function</span> <span class="hljs-title function_">updateCurrentUrlParam</span>(<span class="hljs-params">name, val</span>) &#123;<br>    <span class="hljs-keyword">return</span> <span class="hljs-title function_">updateUrlParam</span>(<span class="hljs-variable language_">document</span>.<span class="hljs-property">location</span>.<span class="hljs-property">href</span>, name, val)<br>&#125;<br><span class="hljs-keyword">function</span> <span class="hljs-title function_">getUrlParamToMap</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-keyword">const</span> params = <span class="hljs-variable language_">window</span>.<span class="hljs-property">location</span>.<span class="hljs-title function_">toString</span>().<span class="hljs-title function_">split</span>(<span class="hljs-string">&#x27;\?&#x27;</span>)[<span class="hljs-number">1</span>]<br>    <span class="hljs-keyword">let</span> map = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>();<br>    <span class="hljs-keyword">if</span>(params == <span class="hljs-literal">null</span> || params === <span class="hljs-string">&#x27;&#x27;</span>) <span class="hljs-keyword">return</span> <span class="hljs-string">&#x27;&#x27;</span><br>    params.<span class="hljs-title function_">split</span>(<span class="hljs-string">&#x27;&amp;&#x27;</span>).<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">param</span> =&gt;</span>&#123;<br>        <span class="hljs-keyword">let</span> kv = param.<span class="hljs-title function_">split</span>(<span class="hljs-string">&#x27;=&#x27;</span>);<br>        <span class="hljs-keyword">let</span> k = kv[<span class="hljs-number">0</span>]<br>        <span class="hljs-keyword">let</span> v = kv[<span class="hljs-number">1</span>]<br>        map.<span class="hljs-title function_">set</span>(k,v)<br>    &#125;)<br>    <span class="hljs-keyword">return</span> map<br>&#125;<br><span class="hljs-keyword">function</span> <span class="hljs-title function_">getUrlParamToJSON</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-keyword">let</span> obj= <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">create</span>(<span class="hljs-literal">null</span>)<br>    <span class="hljs-keyword">let</span> map = <span class="hljs-title function_">getUrlParamToMap</span>();<br>    <span class="hljs-keyword">if</span>(map == <span class="hljs-literal">null</span> || map === <span class="hljs-string">&#x27;&#x27;</span>) <span class="hljs-keyword">return</span>;<br>    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span>[k,v] <span class="hljs-keyword">of</span> map) &#123;<br>        k = <span class="hljs-built_in">decodeURI</span>(k)<br>        v = <span class="hljs-built_in">decodeURI</span>(v)<br>        obj[k] = v;<br>    &#125;<br>    <span class="hljs-keyword">return</span> <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>(obj)<br>&#125;<br><br><br></code></pre></td></tr></table></figure>
<h2 id="功能一：直接获取替换参数值后的URL"><a href="#功能一：直接获取替换参数值后的URL" class="headerlink" title="功能一：直接获取替换参数值后的URL"></a>功能一：直接获取替换参数值后的URL</h2><p>比如当前地址栏的URL为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">user/query?<span class="hljs-built_in">id</span>=1&amp;roleName=普通用户<br></code></pre></td></tr></table></figure>

<p>此时将查询用户ID为1，身份是普通用户的所有用户，当要切换查询的用户身份时，可以通过这个函数直接获取对应的URL</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-title function_">updateCurrentUrlParam</span>(<span class="hljs-string">&#x27;roleName&#x27;</span>, <span class="hljs-string">&#x27;管理员&#x27;</span>)<br></code></pre></td></tr></table></figure>

<p>那么URL就会变成以下内容（其他的参数不会受影响）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">user/query?<span class="hljs-built_in">id</span>=1&amp;roleName=管理员<br></code></pre></td></tr></table></figure>

<h2 id="功能二：清空URL除第一个以外的参数"><a href="#功能二：清空URL除第一个以外的参数" class="headerlink" title="功能二：清空URL除第一个以外的参数"></a>功能二：清空URL除第一个以外的参数</h2><p>比如当前地址栏请求的URL为：</p>
<figure class="highlight dts"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs dts">user/query?pageN<span class="hljs-attr">ow</span><span class="hljs-operator">=</span><span class="hljs-number">1</span><span class="hljs-variable">&amp;username</span>=尤你<span class="hljs-variable">&amp;</span>roleN<span class="hljs-attr">ame</span><span class="hljs-operator">=</span>管理员<br></code></pre></td></tr></table></figure>

<p>由于笔者固定第一个参数表示页数（分页查询），所以这里第一个参数不能清除，在clearURIExceptPageNow() 函数里保留了第一个参数，执行后的结果：</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs routeros">user/query?<span class="hljs-attribute">pageNow</span>=1<br></code></pre></td></tr></table></figure>

<h2 id="功能三：封装URL的参数为Map-x2F-JSON类型"><a href="#功能三：封装URL的参数为Map-x2F-JSON类型" class="headerlink" title="功能三：封装URL的参数为Map&#x2F;JSON类型"></a>功能三：封装URL的参数为Map&#x2F;JSON类型</h2><p>之前的函数都是基于URL内容上的修改，本质上都是<strong>字符串</strong>类型，主要用于修改当前的地址栏信息。</p>
<p>接下来是对其类型的封装，这样有助于通过AJAX请求向后台传递数据，直接将URL的参数传递到后台进行处理。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-title function_">getUrlParamToJSON</span>() 	<span class="hljs-comment">// 将当前地址栏的参数值封装成JSON字符串（可传递到后台）</span><br><br><span class="hljs-title function_">getUrlParamToMap</span>()		<span class="hljs-comment">// 将当前地址栏的参数封装成map类型的对象</span><br></code></pre></td></tr></table></figure>


<h1 id="二、JQuery-AJAX-通过Map传输数据"><a href="#二、JQuery-AJAX-通过Map传输数据" class="headerlink" title="二、JQuery AJAX 通过Map传输数据"></a>二、JQuery AJAX 通过Map传输数据</h1><hr>
<p>有了之前的工具函数后，现在操作URL的参数变得特别灵活，以获取用户信息为例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">function</span> <span class="hljs-title function_">loadData</span>(<span class="hljs-params"></span>)&#123;<br>    $.<span class="hljs-title function_">ajax</span>(&#123;<br>        <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/admin/user/query&#x27;</span>,<br>        <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-title function_">getUrlParamToJSON</span>(),<br>        <span class="hljs-attr">dataType</span>: <span class="hljs-string">&#x27;JSON&#x27;</span>,<br>        <span class="hljs-attr">contentType</span>: <span class="hljs-string">&#x27;application/json;charset=UTF-8&#x27;</span>,<br>        <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span>&#123;<br>            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err)<br>        &#125;,<br>        <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span>&#123;<br>	        <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(data)<br>            <span class="hljs-comment">//...</span><br>        &#125;<br>    &#125;)<br>&#125;<br></code></pre></td></tr></table></figure>
<p><strong>Controller层：</strong> </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller.admin;<br><br><span class="hljs-keyword">import</span> com.github.pagehelper.PageHelper;<br><span class="hljs-keyword">import</span> com.github.pagehelper.PageInfo;<br><span class="hljs-keyword">import</span> com.uni.base.RestResponse;<br><span class="hljs-keyword">import</span> com.uni.pojo.User;<br><span class="hljs-keyword">import</span> com.uni.service.UserService;<br><span class="hljs-keyword">import</span> com.uni.utils.PageUtil;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.*;<br><br><span class="hljs-keyword">import</span> java.io.UnsupportedEncodingException;<br><span class="hljs-keyword">import</span> java.net.URLDecoder;<br><span class="hljs-keyword">import</span> java.util.HashMap;<br><span class="hljs-keyword">import</span> java.util.List;<br><span class="hljs-keyword">import</span> java.util.Map;<br><br><span class="hljs-meta">@RestController</span><br><span class="hljs-meta">@RequestMapping(&quot;/admin/user&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserAdminController</span> &#123;<br>    <span class="hljs-meta">@Autowired</span><br>    UserService userService;<br><br>    <span class="hljs-meta">@PostMapping(&quot;/query&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">toAdminUserByPage</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody</span> Map&lt;String, String&gt; paramMap)</span> <span class="hljs-keyword">throws</span> UnsupportedEncodingException &#123;<br>        Map&lt;String, String&gt; map = <span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;&gt;();<br>        <span class="hljs-keyword">for</span> (String param : paramMap.keySet()) &#123;<br>            paramMap.put(URLDecoder.decode(param, <span class="hljs-string">&quot;utf-8&quot;</span>),<br>                    URLDecoder.decode(paramMap.get(param), <span class="hljs-string">&quot;utf-8&quot;</span>));<br>        &#125;<br>        <span class="hljs-comment">// 获取请求的参数</span><br>        <span class="hljs-type">Integer</span> <span class="hljs-variable">pageNow</span> <span class="hljs-operator">=</span> Integer.parseInt(map.getOrDefault(<span class="hljs-string">&quot;pageNow&quot;</span>, <span class="hljs-string">&quot;1&quot;</span>));<br>        PageHelper.startPage(pageNow, <span class="hljs-number">5</span>);<br><br>        List&lt;User&gt; usersInfo = userService.getUserByMapPojos(paramMap);<br>        <span class="hljs-type">PageInfo</span> <span class="hljs-variable">pageInfo</span> <span class="hljs-operator">=</span> PageUtil.setPageInfo(pageNow, <span class="hljs-number">5</span>, usersInfo);<br>        <span class="hljs-keyword">return</span> RestResponse.ok(<span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;String, Object&gt;()&#123;&#123;<br>            put(<span class="hljs-string">&quot;usersInfo&quot;</span>, usersInfo);<br>            put(<span class="hljs-string">&quot;pageInfo&quot;</span>, pageInfo);<br>        &#125;&#125;).toJSONString();<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>这里需要注意，在传递<strong>中文参数</strong>的时候，URL对其进行了转码，所以在后台接收到的数据默认是转码后的结果，比如在地址栏输入</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">http:<span class="hljs-regexp">//</span>localhost:<span class="hljs-number">8080</span>/测试<br></code></pre></td></tr></table></figure>
<p>然后手动复制这个地址，再粘贴后</p>
<figure class="highlight llvm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs llvm"><span class="hljs-symbol">http:</span>//localhost:<span class="hljs-number">8080</span>/<span class="hljs-variable">%E6</span><span class="hljs-variable">%B5</span><span class="hljs-variable">%8</span>B<span class="hljs-variable">%E8</span><span class="hljs-variable">%AF</span><span class="hljs-variable">%95</span><br></code></pre></td></tr></table></figure>
<p>所以在Controller层接收的参数值就会是这个%E6%B5%8B%E8%AF%95，可以通过JavaEE原生的包<code>java.net.URLDecoder</code>里提供的decode方法进行解码，比如：（这里笔者将Map的KV都进行了转码）：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java">paramMap.put(URLDecoder.decode(param, <span class="hljs-string">&quot;utf-8&quot;</span>), URLDecoder.decode(paramMap.get(param), <span class="hljs-string">&quot;utf-8&quot;</span>));<br></code></pre></td></tr></table></figure>

<p>同样地，之前在前端的JS文件中也进行了解码（防止中文乱码）</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs javascript">thisURL = <span class="hljs-built_in">decodeURI</span>(thisURL)<br></code></pre></td></tr></table></figure>
<h1 id="三、前后端分离思路：动态渲染Ajax请求返回的数据"><a href="#三、前后端分离思路：动态渲染Ajax请求返回的数据" class="headerlink" title="三、前后端分离思路：动态渲染Ajax请求返回的数据"></a>三、前后端分离思路：动态渲染Ajax请求返回的数据</h1><hr>
<p>在这个项目里，笔者一开始是使用Thymeleaf模板引擎渲染数据的，之前要么通过session获取数据，要么通过Controller层在Model对象里写入的数据，而现在则是通过JSON数据，关于数据库的页面就通过JS来渲染，比如渲染用户的信息：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs java">function <span class="hljs-title function_">renderRoleInfo</span><span class="hljs-params">(roleInfo)</span>&#123;<br><br>    $(<span class="hljs-string">&#x27;#tbody-role&#x27;</span>).html(<span class="hljs-string">&#x27;&#x27;</span>)		<span class="hljs-comment">// 先清空内容</span><br>    $.each(roleInfo, (index, user) =&gt;&#123;<br>         $(<span class="hljs-string">&#x27;#tbody-role&#x27;</span>).append(`<br>          &lt;tr valign=<span class="hljs-string">&quot;baseline&quot;</span>&gt;<br>                &lt;td&gt;&lt;input type=<span class="hljs-string">&quot;checkbox&quot;</span> class=<span class="hljs-string">&quot;cb_role&quot;</span> data-code=<span class="hljs-string">&quot;$&#123;user[&#x27;code&#x27;]&#125;&quot;</span>&gt;&lt;/td&gt;<br>                &lt;td&gt;$&#123;user[<span class="hljs-string">&#x27;code&#x27;</span>]&#125;&lt;/td&gt;<br>                &lt;td&gt;$&#123;user[<span class="hljs-string">&#x27;role&#x27;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&#x27;roleName&#x27;</span>]&#125;&lt;/td&gt;<br>                &lt;td&gt;<br>                     &lt;button class=<span class="hljs-string">&quot;btn btn-primary&quot;</span> onclick=<span class="hljs-string">&quot;updateRole(&#x27;$&#123;user[&#x27;code&#x27;]&#125;&#x27;, &#x27;up&#x27;)&quot;</span>&gt;晋升&lt;/button&gt;<br>                     &lt;button class=<span class="hljs-string">&quot;btn btn-warning&quot;</span> onclick=<span class="hljs-string">&quot;updateRole(&#x27;$&#123;user[&#x27;code&#x27;]&#125;&#x27;, &#x27;down&#x27;)&quot;</span>&gt;降级&lt;/button&gt;<br>                     &lt;button class=<span class="hljs-string">&quot;btn btn-danger&quot;</span>&gt;禁用&lt;/button&gt;<br>                &lt;/td&gt;<br>          &lt;/tr&gt;`)<br>    &#125;)<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>不难发现，这个和ThymeLeaf类似，使用 &#96; 符号标记HTML代码，然后可以在里面通过${}取JS文件里的变量值。</p>
<p>还有个问题就是它在什么时候调用？笔者采取的是在AJAX请求获取到数据的时候进行渲染</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">function</span> <span class="hljs-title function_">loadData</span>(<span class="hljs-params"></span>)&#123;<br>    $.<span class="hljs-title function_">ajax</span>(&#123;<br>        <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/admin/user/query&#x27;</span>,<br>        <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-title function_">getUrlParamToJSON</span>(),<br>        <span class="hljs-attr">dataType</span>: <span class="hljs-string">&#x27;JSON&#x27;</span>,<br>        <span class="hljs-attr">contentType</span>: <span class="hljs-string">&#x27;application/json;charset=UTF-8&#x27;</span>,<br>        <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span>&#123;<br>            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err)<br>            <span class="hljs-title function_">open_toast</span>(<span class="hljs-string">&#x27;fail&#x27;</span>, <span class="hljs-string">&quot;获取用户数据失败!&quot;</span>)<br>        &#125;,<br>        <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span>&#123;<br>            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data)<br>            <span class="hljs-keyword">if</span>(data[<span class="hljs-string">&#x27;code&#x27;</span>] === <span class="hljs-number">1</span>)&#123;<br>                $(<span class="hljs-string">&#x27;#userTbody&#x27;</span>).<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;&#x27;</span>)<br>                <span class="hljs-comment">// 渲染搜索的标签</span><br>                <span class="hljs-title function_">loadSearchTag</span>()<br>                <span class="hljs-comment">// 设置渲染延迟</span><br>                <span class="hljs-built_in">setTimeout</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>                    <span class="hljs-comment">// 渲染用户信息</span><br>                    <span class="hljs-title function_">loadUserInfo</span>(data[<span class="hljs-string">&#x27;response&#x27;</span>][<span class="hljs-string">&#x27;usersInfo&#x27;</span>])<br>                    <span class="hljs-comment">// 渲染分页信息</span><br>                    <span class="hljs-title function_">loadPageInfo</span>(data[<span class="hljs-string">&#x27;response&#x27;</span>][<span class="hljs-string">&#x27;pageInfo&#x27;</span>])<br>                    <span class="hljs-comment">// 渲染完毕后关闭加载</span><br>                    $(<span class="hljs-string">&#x27;#searchSpinnerPlaceholder&#x27;</span>).<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;&#x27;</span>)<br>                    <span class="hljs-comment">// 设置结果显示</span><br>                    $(<span class="hljs-string">&#x27;#TextOfShowResultSum&#x27;</span>).<span class="hljs-title function_">text</span>(<span class="hljs-string">`共有<span class="hljs-subst">$&#123;data[<span class="hljs-string">&#x27;response&#x27;</span>][<span class="hljs-string">&#x27;pageInfo&#x27;</span>].total&#125;</span>条结果`</span>)<br>                &#125;, <span class="hljs-number">200</span>)<br>            &#125;<br>        &#125;<br>    &#125;)<br>&#125;<br></code></pre></td></tr></table></figure>


<h1 id="四、两种方式实现筛选查询"><a href="#四、两种方式实现筛选查询" class="headerlink" title="四、两种方式实现筛选查询"></a>四、两种方式实现筛选查询</h1><hr>
<h2 id="思路一：代码限制查询的筛选条件"><a href="#思路一：代码限制查询的筛选条件" class="headerlink" title="思路一：代码限制查询的筛选条件"></a>思路一：代码限制查询的筛选条件</h2><p>数据是通过AJAX获取的，而筛选的条件则显示在URL里，所以接下来可以有两种方式实现筛选的功能，一是通过代码修改Service层业务逻辑处理（繁琐），二是通过改写Mapper映射文件SQL语句（推荐），由于笔者是通过MyBatis逆向工程生成的DAO层接口以及实现的映射文件，它提供了原生的一些增删改查接口，所以没有自己写多表查询的SQL（使用的方法1），在Service层通过简单的SQL语句实现查询的条件限制，之后就用方法2进行了优化，这里都做一个记录吧…</p>
<p><strong>实现效果：</strong><br><img src="https://img-blog.csdnimg.cn/8cfb712ef93e4c1ab978277c8bf18b1b.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><strong>JS关键代码：</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-comment">/* 选择搜索的条件触发函数 */</span><br>$(<span class="hljs-string">&#x27;.nav-search ul li a&#x27;</span>).<span class="hljs-title function_">click</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) &#123;<br>    $wrapper = $(<span class="hljs-string">&#x27;#searchWrapper&#x27;</span>)<br>    $wrapper.<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;&#x27;</span>)<br>    <span class="hljs-keyword">const</span> searchType = $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">text</span>();<br>    <span class="hljs-comment">/* 添加地址 */</span><br>    <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;详细地址&#x27;</span>)&#123;<br>        $wrapper.<span class="hljs-title function_">html</span>(<span class="hljs-string">`&lt;div class=&quot;pt-2&quot;&gt;</span><br><span class="hljs-string">            省份</span><br><span class="hljs-string">            &lt;select name=&quot;searchProv&quot;&gt;</span><br><span class="hljs-string">                &lt;option value=&quot;*&quot; data-code=&quot;*&quot;&gt;请选择&lt;/option&gt;</span><br><span class="hljs-string">            &lt;/select&gt;</span><br><span class="hljs-string">            市区</span><br><span class="hljs-string">            &lt;select name=&quot;searchCity&quot;&gt;</span><br><span class="hljs-string">                &lt;option value=&quot;*&quot; data-code=&quot;*&quot;&gt;请选择&lt;/option&gt;</span><br><span class="hljs-string">            &lt;/select&gt;</span><br><span class="hljs-string">            地区</span><br><span class="hljs-string">            &lt;select name=&quot;searchArea&quot;&gt;</span><br><span class="hljs-string">                &lt;option value=&quot;*&quot; data-code=&quot;*&quot;&gt;请选择&lt;/option&gt;</span><br><span class="hljs-string">            &lt;/select&gt;</span><br><span class="hljs-string">            详细地址</span><br><span class="hljs-string">            &lt;input name=&quot;searchDetail&quot;&gt;</span><br><span class="hljs-string">        &lt;/div&gt;`</span>)<br>        <span class="hljs-title function_">loadSearchAddress</span>()<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;名称&#x27;</span>)&#123;<br>        $wrapper.<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;&lt;input id=&quot;input-search-text&quot; type=&quot;text&quot; name=&quot;searchUserName&quot;&#x27;</span> +<br>            <span class="hljs-string">&#x27; class=&quot;bg-light w-auto mx-1&quot; placeholder=&quot;支持正则表达式&quot;&gt;&#x27;</span>)<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;性别&#x27;</span>)&#123;<br>        $wrapper.<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;&lt;select name=&quot;searchGender&quot;&gt;\n&#x27;</span> +<br>            <span class="hljs-string">&#x27;&lt;option value=&quot;男&quot;&gt;男&lt;/option&gt;\n&#x27;</span> +<br>            <span class="hljs-string">&#x27;&lt;option value=&quot;女&quot;&gt;女&lt;/option&gt;\n&#x27;</span> +<br>            <span class="hljs-string">&#x27;&lt;/select&gt;&#x27;</span>)<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;生日&#x27;</span>)&#123;<br>        $wrapper.<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;从&amp;nbsp;&#x27;</span> +<br>            <span class="hljs-string">&#x27;&lt;input type=&quot;date&quot; name=&quot;searchBirthdayBegin&quot; value=&quot;2022-02-14&quot;&gt;&#x27;</span> +<br>            <span class="hljs-string">&#x27;&amp;nbsp;至&amp;nbsp;&#x27;</span> +<br>            <span class="hljs-string">&#x27;&lt;input type=&quot;date&quot; name=&quot;searchBirthdayEnd&quot; value=&quot;2022-02-14&quot;&gt;&#x27;</span>)<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;电话&#x27;</span>)&#123;<br>        $wrapper.<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;&lt;input id=&quot;input-search-text&quot; type=&quot;text&quot; name=&quot;searchPhone&quot;&#x27;</span> +<br>            <span class="hljs-string">&#x27; class=&quot;bg-light w-auto mx-1&quot; placeholder=&quot;支持正则表达式&quot;&gt;&#x27;</span>)<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;ID&#x27;</span>)&#123;<br>        $wrapper.<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;范围&amp;nbsp;&#x27;</span> +<br>            <span class="hljs-string">&#x27;&lt;input type=&quot;number&quot; name=&quot;searchIDBegin&quot; value=&quot;1&quot;&gt;&#x27;</span> +<br>            <span class="hljs-string">&#x27;&amp;nbsp;—&amp;nbsp;&lt;/div&gt;&#x27;</span> +<br>            <span class="hljs-string">&#x27;&lt;input type=&quot;number&quot; name=&quot;searchIDEnd&quot; value=&quot;1&quot;&gt;\n&#x27;</span>)<br>    &#125;<br>    $(<span class="hljs-string">&#x27;#label-search-type&#x27;</span>).<span class="hljs-title function_">text</span>(searchType)<br>&#125;)<br><br><span class="hljs-comment">/* 动态渲染搜索条件的标签 */</span><br><span class="hljs-keyword">function</span> <span class="hljs-title function_">ualert</span>(<span class="hljs-params">searchType, searchText, alertStyle</span>) &#123;<br>    <span class="hljs-keyword">let</span> wrapper = $(<span class="hljs-string">&#x27;&lt;div class=&quot;div-search-condition mx-3 col-md-3 pt-2 pb-1 fade show alert alert-&#x27;</span> + alertStyle<br>        + <span class="hljs-string">&#x27; alert-dismissible&quot; role=&quot;alert&quot; data-type=&quot;&#x27;</span> + searchType + <span class="hljs-string">&#x27;&quot; data-text=&quot;&#x27;</span> + searchText +<span class="hljs-string">&#x27;&quot;&gt;&#x27;</span> +<br>        searchType + <span class="hljs-string">&#x27; :&#x27;</span> + searchText + <span class="hljs-string">&#x27;&lt;button type=&quot;button&quot; class=&quot;btn-close btn-sm pt-3 pb-1&quot; data-bs-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;&#x27;</span> +<br>        <span class="hljs-string">&#x27;&lt;/button&gt;&lt;/div&gt;&#x27;</span>)<br><br>    $(<span class="hljs-string">&#x27;#searchAlertPlaceholder&#x27;</span>).<span class="hljs-title function_">append</span>(wrapper)<br>&#125;<br><br><span class="hljs-comment">/* 添加筛选标签 */</span><br>$(<span class="hljs-string">&#x27;#btn-add-search&#x27;</span>).<span class="hljs-title function_">click</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)&#123;<br>    <span class="hljs-keyword">let</span> count = $(<span class="hljs-string">&#x27;.div-search-condition&#x27;</span>).<span class="hljs-property">length</span><br><br>    <span class="hljs-comment">// 限制1: 筛选标签数量 &lt;=3</span><br>    <span class="hljs-keyword">if</span>(count &gt;= <span class="hljs-number">3</span>) &#123;<br>        <span class="hljs-title function_">open_toast</span>(<span class="hljs-string">&#x27;fail&#x27;</span>, <span class="hljs-string">&#x27;目前最多支持添加三个标签&#x27;</span>)<br>        <span class="hljs-keyword">return</span> ;<br>    &#125;<br>    <span class="hljs-keyword">let</span> searchType = $(<span class="hljs-string">&#x27;#label-search-type&#x27;</span>).<span class="hljs-title function_">text</span>()<br>    <span class="hljs-keyword">let</span> searchText = <span class="hljs-string">&#x27;&#x27;</span><br>    <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;名称&#x27;</span>)&#123;<br>        searchText = $(<span class="hljs-string">&#x27;input[name=&quot;searchUserName&quot;]&#x27;</span>).<span class="hljs-title function_">val</span>()<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;性别&#x27;</span>)&#123;<br>        searchText = $(<span class="hljs-string">&#x27;select[name=&quot;searchGender&quot;]&#x27;</span>).<span class="hljs-title function_">val</span>()<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;生日&#x27;</span>)&#123;<br>        searchText = $(<span class="hljs-string">&#x27;input[name=&quot;searchBirthdayBegin&quot;]&#x27;</span>).<span class="hljs-title function_">val</span>() + <span class="hljs-string">&#x27;到&#x27;</span><br>            $(<span class="hljs-string">&#x27;input[name=&quot;searchBirthdayEnd&quot;]&#x27;</span>).<span class="hljs-title function_">val</span>()<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;详细地址&#x27;</span>)&#123;<br>        searchText = $selectProv.<span class="hljs-title function_">val</span>() + <span class="hljs-string">&#x27;-&#x27;</span> + $selectCity.<span class="hljs-title function_">val</span>() + <span class="hljs-string">&#x27;-&#x27;</span><br>            + $selectArea.<span class="hljs-title function_">val</span>() + <span class="hljs-string">&#x27;-&#x27;</span> + ($inputDetail.<span class="hljs-title function_">val</span>() === <span class="hljs-string">&#x27;&#x27;</span> ? <span class="hljs-string">&#x27;*&#x27;</span> : $inputDetail.<span class="hljs-title function_">val</span>())<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;ID&#x27;</span>)&#123;<br>        searchText = $(<span class="hljs-string">&#x27;input[name=&quot;searchIDBegin&quot;]&#x27;</span>).<span class="hljs-title function_">val</span>() + <span class="hljs-string">&#x27;到&#x27;</span> +<br>            $(<span class="hljs-string">&#x27;input[name=&quot;searchIDEnd&quot;]&#x27;</span>).<span class="hljs-title function_">val</span>()<br>    &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(searchType === <span class="hljs-string">&#x27;电话&#x27;</span>)&#123;<br>        searchText = $(<span class="hljs-string">&#x27;input[name=&quot;searchPhone&quot;]&#x27;</span>).<span class="hljs-title function_">val</span>()<br>    &#125;<br>    <span class="hljs-comment">// 限制2: 筛选内容不为空</span><br>    <span class="hljs-keyword">if</span>(searchText == <span class="hljs-literal">null</span> || searchText === <span class="hljs-string">&#x27;&#x27;</span>)<br>        <span class="hljs-title function_">open_toast</span>(<span class="hljs-string">&#x27;warning&#x27;</span>, <span class="hljs-string">&#x27;请输入筛选的条件&#x27;</span>)<br>    <span class="hljs-comment">// 限制3: 筛选类型不能重复</span><br>    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(<span class="hljs-title function_">hasSearchType</span>(searchType)) &#123;<br>        <span class="hljs-title function_">open_toast</span>(<span class="hljs-string">&#x27;warning&#x27;</span>, <span class="hljs-string">&#x27;当前筛选的类型已存在!&#x27;</span>)<br>    &#125; <span class="hljs-keyword">else</span><br>        <span class="hljs-title function_">ualert</span>(searchType, searchText, <span class="hljs-string">&#x27;success&#x27;</span>)<br>&#125;)<br><br><span class="hljs-comment">// 搜索功能</span><br>$(<span class="hljs-string">&#x27;#btn-start-search&#x27;</span>).<span class="hljs-title function_">click</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)&#123;<br><br>    <span class="hljs-comment">// 显示加载图标</span><br>    <span class="hljs-keyword">let</span> reqUrl = <span class="hljs-title function_">clearURIExceptPageNow</span>()<br>    <span class="hljs-comment">// 封装表单信息</span><br>    <span class="hljs-keyword">let</span> reqData = []<br>    $(<span class="hljs-string">&#x27;.div-search-condition&#x27;</span>).<span class="hljs-title function_">each</span>(<span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)&#123;<br>        reqData.<span class="hljs-title function_">push</span>(&#123;<br>            <span class="hljs-attr">name</span>: $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;type&#x27;</span>),<br>            <span class="hljs-attr">value</span>: $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;text&#x27;</span>)<br>        &#125;)<br>        reqUrl = <span class="hljs-title function_">updateUrlParam</span>(reqUrl, $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;type&#x27;</span>), $(<span class="hljs-variable language_">this</span>).<span class="hljs-title function_">data</span>(<span class="hljs-string">&#x27;text&#x27;</span>))<br>    &#125;)<br>    <span class="hljs-comment">// 将页数默认为第一页</span><br>    reqUrl = <span class="hljs-title function_">updateUrlParam</span>(reqUrl, <span class="hljs-string">&#x27;pageNow&#x27;</span>, <span class="hljs-string">&#x27;1&#x27;</span>)<br>    <span class="hljs-comment">// 更换地址</span><br>    <span class="hljs-variable language_">window</span>.<span class="hljs-property">location</span> = reqUrl<br>    $.<span class="hljs-title function_">ajax</span>(&#123;<br>        <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/admin/user/search&#x27;</span>,<br>        <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>(reqData),<br>        <span class="hljs-attr">dataType</span>: <span class="hljs-string">&#x27;JSON&#x27;</span>,<br>        <span class="hljs-attr">contentType</span>: <span class="hljs-string">&#x27;application/json;charset=UTF-8&#x27;</span>,<br>        <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> &#123;<br>            <span class="hljs-title function_">open_toast</span>(<span class="hljs-string">&#x27;fail&#x27;</span>, <span class="hljs-string">&quot;请求失败!&quot;</span>)<br>        &#125;,<br>        <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span>&#123;<br>            <span class="hljs-keyword">if</span>(data[<span class="hljs-string">&#x27;code&#x27;</span>] === <span class="hljs-number">1</span>) &#123;<br>                <span class="hljs-title function_">loadUserInfo</span>(data[<span class="hljs-string">&#x27;response&#x27;</span>][<span class="hljs-string">&#x27;usersInfo&#x27;</span>])<br>                <span class="hljs-title function_">loadPageInfo</span>(data[<span class="hljs-string">&#x27;response&#x27;</span>][<span class="hljs-string">&#x27;pageInfo&#x27;</span>])<br>                $(<span class="hljs-string">&#x27;#searchSpinnerPlaceholder&#x27;</span>).<span class="hljs-title function_">html</span>(<span class="hljs-string">&#x27;&#x27;</span>)<br>            &#125;<br>        &#125;<br>    &#125;)<br>&#125;)<br></code></pre></td></tr></table></figure>

<p><strong>Controller层：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> String <span class="hljs-title function_">toAdminUserByPageBySome</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody</span> Map&lt;String, String&gt; paramMap)</span>&#123;<br>    <span class="hljs-type">int</span> <span class="hljs-variable">pageNow</span> <span class="hljs-operator">=</span> Integer.parseInt(paramMap.getOrDefault(<span class="hljs-string">&quot;pageNow&quot;</span>, <span class="hljs-string">&quot;1&quot;</span>));<br>    PageHelper.startPage(pageNow, <span class="hljs-number">5</span>);<br>    List&lt;User&gt; usersInfo = userService.getUserByMapPojos(paramMap);<br>    <span class="hljs-type">PageInfo</span> <span class="hljs-variable">pageInfo</span> <span class="hljs-operator">=</span> PageUtil.setPageInfo(pageNow, <span class="hljs-number">5</span>, usersInfo);<br>    <span class="hljs-keyword">return</span> RestResponse.ok(<span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;String, Object&gt;()&#123;&#123;<br>        put(<span class="hljs-string">&quot;usersInfo&quot;</span>, usersInfo);<br>        put(<span class="hljs-string">&quot;pageInfo&quot;</span>, pageInfo);<br>    &#125;&#125;).toJSONString();<br>&#125;<br></code></pre></td></tr></table></figure>

<p><strong>Service层</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> List&lt;User&gt; <span class="hljs-title function_">getUserByMapPojos</span><span class="hljs-params">(Map&lt;String, String&gt; paramMap)</span> &#123;<br>       <span class="hljs-type">UserExample</span> <span class="hljs-variable">userExample</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">UserExample</span>();<br>       UserExample.<span class="hljs-type">Criteria</span> <span class="hljs-variable">criteria</span> <span class="hljs-operator">=</span> userExample.createCriteria();<br>       <span class="hljs-type">boolean</span> <span class="hljs-variable">up</span> <span class="hljs-operator">=</span> <span class="hljs-literal">true</span>;<br>       <span class="hljs-keyword">for</span> (String param : paramMap.keySet()) &#123;<br>           <span class="hljs-type">String</span> <span class="hljs-variable">value</span> <span class="hljs-operator">=</span> paramMap.get(param);<br>           <span class="hljs-keyword">if</span>(<span class="hljs-string">&quot;orderById&quot;</span>.equals(param))<br>               up = <span class="hljs-string">&quot;up&quot;</span>.equals(value);<br>           <span class="hljs-keyword">if</span> (<span class="hljs-string">&quot;名称&quot;</span>.equals(param)) &#123;<br>               criteria.andUsernameLike(<span class="hljs-string">&quot;%&quot;</span> + value + <span class="hljs-string">&quot;%&quot;</span>);<br>           &#125;<br>           <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-string">&quot;生日&quot;</span>.equals(param)) &#123;<br>               System.out.println(value);<br>           &#125;<br>           <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-string">&quot;性别&quot;</span>.equals(param)) &#123;<br>               <span class="hljs-keyword">if</span> (<span class="hljs-string">&quot;男&quot;</span>.equals(value))<br>                   criteria.andGenderEqualTo(<span class="hljs-number">2</span>);<br>               <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-string">&quot;女&quot;</span>.equals(value))<br>                   criteria.andGenderEqualTo(<span class="hljs-number">1</span>);<br>           &#125;<br>           <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-string">&quot;电话&quot;</span>.equals(param)) &#123;<br>               criteria.andPhoneLike(<span class="hljs-string">&quot;%&quot;</span> + value + <span class="hljs-string">&quot;%&quot;</span>);<br>           &#125;<br>           <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-string">&quot;详细地址&quot;</span>.equals(param)) &#123;<br>               criteria.andAddressLike(<span class="hljs-string">&quot;%&quot;</span> + value + <span class="hljs-string">&quot;%&quot;</span>);<br>           &#125;<br>           <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-string">&quot;ID&quot;</span>.equals(param)) &#123;<br>               String[] v = value.split(<span class="hljs-string">&quot;到&quot;</span>);<br>               <span class="hljs-type">int</span> <span class="hljs-variable">begin</span> <span class="hljs-operator">=</span> Integer.parseInt(v[<span class="hljs-number">0</span>]);<br>               <span class="hljs-type">int</span> <span class="hljs-variable">end</span> <span class="hljs-operator">=</span> Integer.parseInt(v[<span class="hljs-number">1</span>]);<br>               criteria.andIdBetween((<span class="hljs-type">long</span>) Math.max(<span class="hljs-number">1</span>, begin), (<span class="hljs-type">long</span>) Math.max(<span class="hljs-number">0</span>, end));<br>           &#125;<br>       &#125;<br><br>       List&lt;User&gt; users = userMapper.selectByExampleWithBLOBs(userExample);<br>       <span class="hljs-keyword">if</span>(!up)&#123;<br>           users.sort(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Comparator</span>&lt;User&gt;() &#123;<br>               <span class="hljs-meta">@Override</span><br>               <span class="hljs-keyword">public</span> <span class="hljs-type">int</span> <span class="hljs-title function_">compare</span><span class="hljs-params">(User o1, User o2)</span> &#123;<br>                   <span class="hljs-keyword">if</span>(o1.getId() &lt; o2.getId())<br>                       <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;<br>                   <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(o1.getId() &gt; o2.getId())<br>                       <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br>                   <span class="hljs-keyword">else</span><br>                       <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>               &#125;<br>           &#125;);<br>       &#125;<br>       <span class="hljs-keyword">return</span> users;<br>   &#125;<br></code></pre></td></tr></table></figure>

<p>DAO层就不放代码了，是MyBatis逆向工程插件的原生代码，想了解其基本使用可参考文章<a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122520640">【点击查看】</a></p>
<h2 id="思路二：通过改写Mapper映射文件实现多表查询-条件限制"><a href="#思路二：通过改写Mapper映射文件实现多表查询-条件限制" class="headerlink" title="思路二：通过改写Mapper映射文件实现多表查询+条件限制"></a>思路二：通过改写Mapper映射文件实现多表查询+条件限制</h2><p><strong>实现效果：</strong><br><img src="https://img-blog.csdnimg.cn/a2c63ef0e754480fb1cf4acd0e48a4e4.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>前端部分就不放了，和之前一样是通过AJAX请求数据的，搜索则是直接修改地址栏的URL</p>
<p><strong>Controller层：</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.controller.admin;<br><br><span class="hljs-keyword">import</span> com.github.pagehelper.PageHelper;<br><span class="hljs-keyword">import</span> com.github.pagehelper.PageInfo;<br><span class="hljs-keyword">import</span> com.uni.base.RestResponse;<br><span class="hljs-keyword">import</span> com.uni.pojo.Role;<br><span class="hljs-keyword">import</span> com.uni.pojo.User;<br><span class="hljs-keyword">import</span> com.uni.service.RoleService;<br><span class="hljs-keyword">import</span> com.uni.service.UserService;<br><span class="hljs-keyword">import</span> com.uni.utils.PageUtil;<br><span class="hljs-keyword">import</span> com.uni.utils.ParamUtil;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;<br><span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.*;<br><br><span class="hljs-keyword">import</span> java.io.UnsupportedEncodingException;<br><span class="hljs-keyword">import</span> java.util.HashMap;<br><span class="hljs-keyword">import</span> java.util.List;<br><span class="hljs-keyword">import</span> java.util.Map;<br><br><span class="hljs-meta">@RestController</span><br><span class="hljs-meta">@RequestMapping(&quot;/admin/role&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">RoleAdminController</span> &#123;<br>    <span class="hljs-meta">@Autowired</span><br>    UserService userService;<br>    <span class="hljs-meta">@Autowired</span><br>    RoleService roleService;<br>    <span class="hljs-meta">@PostMapping(&quot;/query/all&quot;)</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getRoleInfo</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody(required = false)</span> Map&lt;String, String&gt; paramMap)</span> &#123;<br>        ParamUtil.translate(paramMap);<br>        <span class="hljs-type">int</span> <span class="hljs-variable">pageNum</span> <span class="hljs-operator">=</span> Integer.parseInt(paramMap.getOrDefault(<span class="hljs-string">&quot;pageNow&quot;</span>, <span class="hljs-string">&quot;1&quot;</span>));<br>        PageHelper.startPage(pageNum, <span class="hljs-number">5</span>);<br>        List&lt;User&gt; users = userService.getUserRoleByMapPojos(paramMap);<br>        List&lt;Role&gt; roles = roleService.queryAllRole();<br>        <span class="hljs-type">PageInfo</span> <span class="hljs-variable">pageInfo</span> <span class="hljs-operator">=</span> PageUtil.setPageInfo(pageNum, <span class="hljs-number">5</span>, users);<br>        <span class="hljs-keyword">return</span> RestResponse.ok(<span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;String, Object&gt;()&#123;&#123;<br>            put(<span class="hljs-string">&quot;pageInfo&quot;</span>, pageInfo);<br>            put(<span class="hljs-string">&quot;roleInfo&quot;</span>, roles);<br>        &#125;&#125;).toJSONString();<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>上述代码使用的 ParamUtil工具类是自定义的，就是之前URL编码的问题，内容如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.utils;<br><br><span class="hljs-keyword">import</span> java.io.UnsupportedEncodingException;<br><span class="hljs-keyword">import</span> java.net.URLDecoder;<br><span class="hljs-keyword">import</span> java.util.Map;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">ParamUtil</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Map&lt;String, String&gt; <span class="hljs-title function_">translate</span><span class="hljs-params">(Map&lt;String, String&gt; map)</span> &#123;<br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-keyword">for</span> (String key : map.keySet()) &#123;<br>                map.put(URLDecoder.decode(key, <span class="hljs-string">&quot;utf-8&quot;</span>),<br>                        URLDecoder.decode(map.get(key), <span class="hljs-string">&quot;utf-8&quot;</span>));<br>            &#125;<br>        &#125;<span class="hljs-keyword">catch</span>(UnsupportedEncodingException e)&#123;<br>            e.printStackTrace();<br>        &#125;<br>        <span class="hljs-keyword">return</span> map;<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p><strong>Service层：</strong> 直接调用Mapper接口即可，相比之前的代码简化了许多</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Override</span><br><span class="hljs-keyword">public</span> List&lt;User&gt; <span class="hljs-title function_">getUserRoleByMapPojos</span><span class="hljs-params">(Map&lt;String, String&gt; paramMap)</span> &#123;<br>    <span class="hljs-keyword">return</span> userMapper.selectCodeWithRole(paramMap);<br>&#125;<br></code></pre></td></tr></table></figure>
<p><strong>DAO层：</strong><code>UserMapper.xml</code> 目前笔者对角色只做了角色名称和用户账号进行了筛选</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;selectCodeWithRole&quot;</span> <span class="hljs-attr">parameterType</span>=<span class="hljs-string">&quot;Map&quot;</span> <span class="hljs-attr">resultMap</span>=<span class="hljs-string">&quot;userWithRole&quot;</span>&gt;</span><br>  SELECT user.code, r.id, r.roleName<br>  FROM v2_user AS user<br>         LEFT JOIN v2_user_role AS ur<br>                   ON user.id = ur.userId<br>         LEFT JOIN v2_role AS r<br>                   ON ur.roleId = r.id<br>  <span class="hljs-tag">&lt;<span class="hljs-name">where</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">foreach</span> <span class="hljs-attr">collection</span>=<span class="hljs-string">&quot;map&quot;</span> <span class="hljs-attr">item</span>=<span class="hljs-string">&quot;value&quot;</span> <span class="hljs-attr">index</span>=<span class="hljs-string">&quot;key&quot;</span> <span class="hljs-attr">separator</span>=<span class="hljs-string">&quot;AND&quot;</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;key == &#x27;roleName&#x27;&quot;</span>&gt;</span><br>              r.roleName = #&#123;value&#125;<br>          <span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">test</span>=<span class="hljs-string">&quot;key == &#x27;code&#x27;&quot;</span>&gt;</span><br>              user.code LIKE CONCAT(&#x27;%&#x27;,#&#123;value&#125;, &#x27;%&#x27;)<br>          <span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">foreach</span>&gt;</span><br>  <span class="hljs-tag">&lt;/<span class="hljs-name">where</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span><br><br><span class="hljs-tag">&lt;<span class="hljs-name">resultMap</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;userWithRole&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;com.uni.pojo.User&quot;</span>&gt;</span><br>  <span class="hljs-tag">&lt;<span class="hljs-name">result</span> <span class="hljs-attr">column</span>=<span class="hljs-string">&quot;code&quot;</span> <span class="hljs-attr">property</span>=<span class="hljs-string">&quot;code&quot;</span>/&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">collection</span> <span class="hljs-attr">property</span>=<span class="hljs-string">&quot;role&quot;</span> <span class="hljs-attr">ofType</span>=<span class="hljs-string">&quot;com.uni.pojo.Role&quot;</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">result</span> <span class="hljs-attr">column</span>=<span class="hljs-string">&quot;id&quot;</span> <span class="hljs-attr">property</span>=<span class="hljs-string">&quot;id&quot;</span>/&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">result</span> <span class="hljs-attr">column</span>=<span class="hljs-string">&quot;roleName&quot;</span> <span class="hljs-attr">property</span>=<span class="hljs-string">&quot;roleName&quot;</span>/&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">collection</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">resultMap</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>这里用到了用户角色表（中间表）进行角色的查询，三张表的结构如下：<br><img src="https://img-blog.csdnimg.cn/00c9e3ca41584a4da03d1b2d790ce133.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2-0/" class="category-chain-item">项目实战:购物系统v2.0</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaWeb/">#JavaWeb</a>
      
        <a href="/tags/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2-0/">#项目实战:购物系统v2.0</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Web项目实战 _ 购物系统v2.0 _ 开发记录（八）前后端分离初步思路 _ JS处理URL参数实用函数 _ AJAX 向后台传递Map类型数据 _ MyBatis多表查询优化</div>
      <div>http://example.com/2022/02/17/Web项目实战 _ 购物系统v2.0 _ 开发记录（八）前后端分离初步思路 _ JS处理URL参数实用函数 _ AJAX 向后台传递Map类型数据 _ MyBatis多表查询优化/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年2月17日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/02/17/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E4%B9%9D%EF%BC%89Controller%E5%B1%82%E8%BF%94%E5%9B%9E%E6%95%B0%E6%8D%AE%E7%9A%84%E5%B0%81%E8%A3%85%20_%20%E5%95%86%E5%93%81%E6%89%B9%E9%87%8F%E6%93%8D%E4%BD%9C%20_%20%E4%BA%94%E8%A1%A8%E8%81%94%E7%AB%8B%E5%AE%9E%E7%8E%B0%E5%95%86%E5%93%81%E6%90%9C%E7%B4%A2/" title="Web项目实战 _ 购物系统v2.0 _ 开发记录（九）Controller层返回数据的封装 _ 商品批量操作 _ 五表联立实现商品搜索">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Web项目实战 _ 购物系统v2.0 _ 开发记录（九）Controller层返回数据的封装 _ 商品批量操作 _ 五表联立实现商品搜索</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/02/13/Hadoop%20_%20MapReduce%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%20_%20Partitioner%E5%88%86%E5%8C%BA%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%88%86%E5%8C%BA%E7%AD%96%E7%95%A5%E6%A1%88%E4%BE%8B%20_%20WritableComparable%20%E5%85%A8%E6%8E%92%E5%BA%8F%20_%20Combiner%E3%80%81OutputFormat/" title="Hadoop _ MapReduce学习笔记 _ Partitioner分区 自定义分区策略案例 _ WritableComparable 全排序 _ Combiner、OutputFormat">
                        <span class="hidden-mobile">Hadoop _ MapReduce学习笔记 _ Partitioner分区 自定义分区策略案例 _ WritableComparable 全排序 _ Combiner、OutputFormat</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
